
//
// 120329 - AH - (Nesttun Legesenter *) Created.
// 120727 - AH - (Midtun) Responds with array not list as used to.
//

package org.soekrat.server.servlets.ce;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.soekrat.server.io.db.ConversationElement;
import org.soekrat.server.io.db.SoekratDAO;
import org.soekrat.server.io.db.SoekratDAOFactory;
import org.soekrat.server.serialization.ConversationElementSerializable;
import org.soekrat.server.servlets.AbstractSoekratHttpServlet;

/**
 * <p>
 *   Implements request to get all 
 *   {@link ConversationElement}s.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
@SuppressWarnings("serial")
public final class GetAllConversationElementsHttpServlet
  extends AbstractSoekratHttpServlet
{
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public GetAllConversationElementsHttpServlet(){}

  @Override
  protected void handleRequest(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException 
  {
    SoekratDAO dao=new SoekratDAOFactory().create();
            
    List<ConversationElement> coes=dao.getConversationElements();
    List<ConversationElementSerializable> 
      ces=new ArrayList<ConversationElementSerializable>();
    
    for (ConversationElement curr : coes) 
      ces.add(new ConversationElementSerializable(curr));
    
    respond(res, ces.toArray(ConversationElementSerializable.EMPTY_ARRAY));
  }
  
}
